package cuiyt.juc.stream;

import java.util.concurrent.RecursiveTask;

/**
 * @author cyt
 * @create 2020-05-02 8:01
 */
public class forkjoin extends RecursiveTask<Integer> {
    final int n;
    public forkjoin(int n) {
        this.n = n;
    }
    @Override
    protected Integer compute() {
        if (n <= 1) return n;
        forkjoin f1 = new forkjoin(n - 1);
        f1.fork();
        forkjoin f2 = new forkjoin(n - 1);
        f2.fork();
        return f1.join() + f2.join();
    }

}
